import { Cookie, enums, Lockr } from '../../utils'
import router from '../../router/index'
import { resolve } from 'q'
const state = {
  userInfo: {},
  menusInfo:[]
}
const getters = {
  getUserInfo: (state) => {
    if (JSON.stringify(state.userInfo) == '{}') {
      state.userInfo = Cookie.get('STORE_INFO') ? Cookie.get('STORE_INFO') : {}
    }
    return state.userInfo
  },
  getMenusList: (state) => {
    if (state.menusInfo.length == 0) {
      state.menusInfo = Cookie.get('STORE_MENUS') ? Cookie.get('STORE_MENUS') : {}
    }
    return state.menusInfo
  },
}

const mutations = {
  updateMenus(state, list){
    // console.log(list,'list')
    if(list.length != 0){
      state.menusInfo = list
      // Cookie.set({
      //   key:'STORE_MENUS',
      //   value: JSON.stringify(state.menusInfo)
      // })
    }
  },
  updateUserInfo(state, info){
    state.userInfo = info
    // Cookie.set({
    //   key:'STORE_INFO',
    //   value: JSON.stringify(state.userInfo)
    // })
    // router.push({name:'83'})
  },
}

const actions = {
  setMenus({ commit }, data){
    commit('updateMenus', data)
  },
  setUserInfo({commit}, data){
    console.log(data,'userdata')
    commit('updateUserInfo', data)
  },
  setMenusAndUserInfo({commit},list,data){
      commit('updateUserInfo', data)
      commit('updateMenus', list)
  }

}

// jumpLoginPage () {
//   if (process.env.NODE_ENV === 'production') {
//     window.location.href = 'http//'
//   } else {
//     window.location.href = 'http://localhost:8888/'
//   }
// }

export default {
  state,
  getters,
  mutations,
  actions
}
